package com.ddd.demo.lee.数组;

public class 删除有序数组中的重复项 {

    public static void main(String[] args) {

        int[] nums = new int[]{1, 1, 2};

        int i = removeDuplicates(nums);

        System.out.println("i = " + i);

    }

    public static int removeDuplicates(int[] nums) {

        int slow = 0;
        int fast = 1;

        while (fast < nums.length) {
            if (nums[fast] != nums[slow]) {
                nums[slow + 1] = nums[fast];
                slow++;
            }
            fast++;
        }

        return slow + 1;
    }
}
